package org.example.io;

import java.io.File;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;

public class TestZipOutputStream {

    public static void main(String[] args) throws Exception {
        File file = new File("D:\\tmp");
        //创建压缩流
        ZipOutputStream stream = new ZipOutputStream(new FileOutputStream(new File(file,"a.zip")));
        //压缩文件夹
        ZipEntry entry = new ZipEntry("a.txt");
        stream.putNextEntry(entry);

        FileReader reader = new FileReader("D:\\tmp\\111.txt");
        //读取文件
        int i;
        while ((i = reader.read())!=-1){
            stream.write(i);
        }

        //关闭压缩流
        stream.close();
    }

}
